This Notebook Covers:

Lesson 2A-L2 Filtering


In [109]:
import cv2
import os
import matplotlib.pyplot as plt
from ps0 import *
import numpy as np
%matplotlib inline

In [4]:
driver_path = 'input/ps0-1-a-1.jpg'

driver = cv2.imread(driver_path)
show_img(driver)


Quiz: Add Noise to the Image


In [150]:
np_noise = np.random.normal(0,50,driver.shape)
np_noise = conv_to_uint8(np_noise)
driver_gaussian_2 = cv2.add(driver, np_noise)
driver_gaussian = cv2.add(driver, np_noise)

# I'd like to illustrate something - driver_gaussian_3 is wrong
# because of wrong uint8 adding. To make it correct, we'll have
# to convert the driver and np_noise pixels to floats first,
# clip them, and then cast them to uint8 again.
driver_gaussian_3 = (driver + np_noise)

In [151]:
show_multiple_images({'driver_gaussian_2':driver_gaussian_2,
                      'driver_gaussian':driver_gaussian})



In [142]:
# As explained above, this will be wrong.
show_multiple_images({'driver_gaussian_3':driver_gaussian_3})


Apply a Gaussian Filter to Remove Noise


In [173]:
driver_blur = cv2.GaussianBlur(driver, (7,7), 3)

In [174]:
show_multiple_images({'driver_blur':driver_blur,
                      'driver_gaussian':driver_gaussian})



In [ ]: